<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class FgcmsCheckoutShipping {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty) {
		//contructor function
		$this->db = $db;
		$this->smarty = $smarty;
	}
	
	/* Assigning the content related to the category_id to the 
	 * Smarty-Variable 'PAGE'. Because using ezSql, PAGE is a pointer!
	 * One should be aware of this fact, when PAGE is used in the 
	 * Smarty-Templates. Output is generated ba: {$PAGE->page_content}.
	 */ 
	
	public function view_shipping() {
		$information = FgcmsCustomerBean::getCustomerById($this->db,$_SESSION['cust_id']);
		$allcountry = FgcmsCountryBean::get_all_country($this->db);	
		$method = FgcmsCheckoutBean::get_all_shipping_method($this->db);
		$this->smarty->assign("SALESORDER", $information);
		$this->smarty->assign("SHIPPINGMETHOD", $method);
		$this->smarty->assign('ALLCOUNTRY',$allcountry);
		
	}
	
	public function save_shipping_address() {
		
		//if(isset($_SESSION['delivery'])){
			$country = FgcmsCountryBean::get_country_byId($this->db,$_POST["delivery_country"]);	
			$delivery = array('delivery_gender' => $_POST["delivery_gender"],
					  	  'delivery_firstname' => $_POST["delivery_firstname"],
						  'delivery_lastname' => $_POST["delivery_lastname"],
						  'delivery_company' => $_POST["delivery_company"],
						  'delivery_street_address' => $_POST["delivery_street_address"],
						  'delivery_city' => $_POST["delivery_city"],
						  'delivery_postcode' => $_POST["delivery_postcode"],
						  'delivery_state' => $_POST["delivery_state"],
						  'delivery_country' => $_POST["delivery_country"],
						  'delivery_country_name' => $country->country_name,
						  'delivery_telephone' => $_POST["delivery_telephone"],
						  'delivery_email_address' => $_POST["delivery_email_address"]);	
			//$_SESSION['delivery'] = $delivery;			
			FgcmsCustomerBean::updateCustomerShipping($this->db,$delivery);	  
		//}	
		header("Location: ./?page=checkout_shipping");	
	}
	public function save_shipping() {
		
			$method = FgcmsCheckoutBean::get_shipping_method_by_code($this->db,$_POST["code"]);
			$_SESSION['delivery']['shipping_method'] = $_POST["code"];
			$_SESSION['delivery']['delivery_cost'] = $method->delivery_cost;
			$_SESSION['delivery']['notes'] = $_POST["notes"];
		header("Location: ./?page=checkout_payment");	
	}
}
?>
